//
//  HMRemindMatter.swift
//  HealthMonitoring
//
//  Created by YTYanK on 2018/8/20.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
import SwiftyJSON

class HMRemindMatter: HMViewController {
    var cellHeight: CGFloat = 0
    let table  = UITableView()
    
    var maskView: UIView?
    // 次数
    let numPickerAry = ["一日一次", "一日两次", "一日三次", "一日四次"]
    // 疗程
    let coursePickAry = ["一天", "三天", "一周", "三十天"]
    // 剂量
    let dosePickAry = ["四分之一","三分之一","二分之一","一","二","三","四","五","六","七"]
    // 单位
    let companyAry = ["瓶","片","颗","包"]
   
    /// 配置数据
    var configData:JSON?
    /// 数据
    var reminderJson = JSON()
    /// 选择的日期
    var selecotDate = String()
    // 23小时 数组
    var  hourAry = Array<String>()
    // 59分 数组
    var  minuteAry = Array<String>()
    /// 类型， 数据反回类型 , 默认正常返回
    var isReturnType: String = ""
    /// 入口名称
    var inletName: String = ""
    // 返回Data
   // var dataBlock:((_ data:Data) ->(Void))?
    
    
    var dataList =  JSON()
    var copyDataList = JSON() // 保存第一个模版
    override func setupView() {

        self.initData()
        self.setNavRightView()
        
        view.backgroundColor = UIColor.white//configure.shareConfigure.HMColor2
        view.addSubview(table)
        table.delegate = self
        table.dataSource = self
        table.register(HMRemindMatterCell.classForCoder(), forCellReuseIdentifier: "HMRemindMatterCell")
        table.topAlign(view: view, predicate: "0")
        table.leadingAlign(view: view, predicate: "0")
        table.width(view: view)
        table.height(view: view)

        for n in 0..<59 {
            let nStr =  ((n < 10) ? "0\(n)" : String(n))
            if n < 24 {
                self.hourAry.append("\(nStr)时")
            }
            self.minuteAry.append("\(nStr)分")
        }
        
    }
    // 右保存
    func setNavRightView()  {
        let setBtn =  UIButton(frame: CGRect(x: 0, y: 0, width: 24, height: 24))
        setBtn.setTitle("保存", for: .normal)
        setBtn.setTitleColor(configure.shareConfigure.HMColor1, for: .normal)
        let rightBtn = UIBarButtonItem(customView: setBtn)
        setBtn.addTarget(self, action: #selector(navRightBtn), for: UIControlEvents.touchUpInside)
        let negativeSpacer = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
        negativeSpacer.width = -10
        
        navigationItem.rightBarButtonItems = [negativeSpacer, rightBtn]
    }

    @objc func navRightBtn(sender: UIButton)  {

        //HMUtils.showHUD(self)
        
        let copyDataList = self.dataList.arrayValue
        
        var par = Array<Any>()
        var dic = Dictionary<String,Any>()  //每个字典
        var ary = Array<String>() //数组
        var illnessDic = Dictionary<String, Any>()
        

            for list in copyDataList { // 数据抽取
                
                if self.inletName == "医生出诊" {
                    
                    if list["prescId"].stringValue.count > 0 {
                        illnessDic["id"] = list["prescId"].stringValue
                    }
                
                }else {
                    if list["id"].stringValue.count > 0 {
                        dic["id"] = list["id"].stringValue
                    }
                }
                
                dic["intervalMode"] = "1"
                dic["intervalTemplate"] = "1"
                
                
                var items = list["itme"].arrayValue
                ary = []
                print("===>",items)
                for k  in 0..<items.count {
//                    print("item", items[k])
                    let _title = items[k]["title"].stringValue
                    if _title == "疾病名称" {
                        illnessDic["applyIllness"] = items[k]["value"].stringValue
                    }else if _title == "药品名称" {
                        dic["medicineName"] = items[k]["value"].stringValue
                    }else if _title == "服药次数" {
                        let str = items[k]["value"].stringValue
                        for descs  in configData!["timesOneDay"] {
                            if str.contains(descs.1["desc"].stringValue) {
                                dic["timesOneDay"] = descs.1["id"].stringValue
                            }
                        }
                        
                    }else if  _title.contains("吃药时间") {
                        if items[k]["isHides"].boolValue == false {
                            ary.append(items[k]["value"].stringValue)
                        }
                        
                    }else if  _title == "服药时段"  {
                        var n = 0
                        if items[k]["value"].stringValue == "餐前" {
                            n = 1
                        }else {
                            n = 2
                        }
                        dic["takeTime"] = "\(n)"
                    }else if _title == "用量(剂量)" {
                        let str = items[k]["value"].stringValue
                        for descs  in configData!["dosage"] {
                            if str.contains(descs.1["desc"].stringValue) {
                                dic["dosage"] = descs.1["id"].stringValue
                            }
                        }
                        
                        for unit in configData!["dosageUnit"] {
                            if str.contains(unit.1["desc"].stringValue)  {
                                dic["dosageUnit"] = unit.1["id"].stringValue
                            }
                        }
                    }else if _title == "疗程" {
                        let str = items[k]["value"].stringValue
                        
                        for  treatment in configData!["treatment"] {
                            
                            if str.contains(treatment.1["desc"].stringValue) {
                                dic["treatment"] = treatment.1["id"].stringValue
                            }
                        }
                        
                    }else if _title == "开始日期" {
                        //毫秒时间戳
                        dic["startTime"] =  self.selecotDate
                        dic["endTime"] = self.selecotDate
                    }else if _title == "备注" {
                        if self.inletName == "医生出诊" {
                            illnessDic["remark"] = items[k]["value"].stringValue
                        }else {
                            dic["remark"] = items[k]["value"].stringValue
                        }
                    }
                }
                dic["reminderTime"] = ary
                par.append(dic)
            }
            
        
       
         print("打印===>",par)
        
        
        if isReturnType == "data" {
             let bodyStr = self.getJSONString(array: par)
             let bodyData = bodyStr.data(using: String.Encoding.utf8)
             UserDefaults.standard.set(bodyData, forKey: "remindDate")
            // 返回
            let viewC =  self.navigationController?.viewControllers[2] as! InstantMessaging
            self.navigationController?.popToViewController(viewC, animated: true)
        }else {
            
            if self.inletName == "医生出诊" { //区分

                    NetRequestTool.shareInstance.met = .post
                    NetRequestTool.requestForJSON(url: "doctor/doc/prescription", parameters: illnessDic, success: { (json) in
                        
                        for k in 0..<par.count {
                            var dic  = par[k] as! Dictionary<String, Any>
                            dic["prescId"] = json["data"]["id"].stringValue
                            par[k] = dic
                        }
                       
                        let bodyStr = self.getJSONString(array: par)
                        let bodyData = bodyStr.data(using: String.Encoding.utf8)
                        let urlString = configure.shareConfigure.IP + "doctor/doc/presc/medicine"
                        self.requestData(urlString: urlString, bodyData: bodyData!, block: { (newData) -> (Void) in
                            print("大爷", newData)
                            //     self.navigationController?.popViewController(animated: false)
                        })
                    }, fail: { (error, msg) in
                        print("请求错误", msg)
                    }) {}
            }else {
                
                let bodyStr = self.getJSONString(array: par)
                let bodyData = bodyStr.data(using: String.Encoding.utf8)
                let urlString = configure.shareConfigure.IP + "user/medicine/reminder"
                self.requestData(urlString: urlString, bodyData: bodyData!) { (newData) -> (Void) in
                    print("=====>", newData);
                }
            }
            

            
        }
        
       
    }
    
    func initData() {
        
        if self.inletName == "医生出诊" {
           
            self.title = "药物建议"
            self.dataList = [["itme" : [
                
                ["id": 0, "type": "input", "title": "疾病名称", "value": "", "placeholder": "请输入疾病名称"],
                ["id": 1, "type": "input", "title": "备注", "value": ""],
                ["id": 2, "type": "labelArrow", "title":"药品名称", "value": "", "placeholder": "请输入药品名称"],
                ["id": 3, "type": "dropDown", "title":"服药次数","value": "一日1次"],
                ["id": 4, "type": "dropDown", "title": "吃药时间1", "value":"07:00", "isHides" : false],
                ["id": 5, "type": "dropDown", "title": "吃药时间2", "value":"07:10", "isHides" : true],
                ["id": 6, "type": "dropDown", "title": "吃药时间3", "value":"07:20", "isHides" : true],
                ["id": 7, "type": "dropDown", "title": "吃药时间4", "value":"07:30", "isHides" : true],
                
                
                ["id": 8, "type": "radio", "title": "服药时段", "value": "餐前", "itemAry": [["select": false, "title": "餐前"],["select": true, "title": "餐后"]]],
                ["id": 9, "type" : "labelArrow", "title":"用量(剂量)","value": "请选择"],
                ["id": 10,"type" : "labelArrow", "title":"疗程",  "value": ""],
//                ["id": 11,"type" : "label", "title":"开始日期", "value": "2018-11-16"],
                
                //            ["id": 7,"type" : "Button", "ary": ["title":"删除", "color": "red"]],
                ["id": 11,"type" : "button", "title":"新建模版", "color": "blue"],
                ],
                  "indexId": 0,
                  "prescId": "", //疾病id
                  "id": ""
                ]]

        }else {
           self.title  = "编辑药品"
            self.dataList = [["itme" : [
                ["id": 0, "type": "labelArrow", "title":"药品名称", "value": "请输入"],
                ["id": 1, "type": "dropDown", "title":"服药次数","value": "一日1次"],
                ["id": 2, "type": "dropDown", "title": "吃药时间1", "value":"07:00", "isHides" : false],
                ["id": 3, "type": "dropDown", "title": "吃药时间2", "value":"07:10", "isHides" : true],
                ["id": 4, "type": "dropDown", "title": "吃药时间3", "value":"07:20", "isHides" : true],
                ["id": 5, "type": "dropDown", "title": "吃药时间4", "value":"07:30", "isHides" : true],
                
                
                ["id": 6, "type": "radio", "title": "服药时段", "value": "餐前", "itemAry": [["select": false, "title": "餐前"],["select": true, "title": "餐后"]]],
                ["id": 7, "type" : "labelArrow", "title":"用量(剂量)","value": "请选择"],
                ["id": 8,"type" : "labelArrow", "title":"疗程",  "value": ""],
                ["id": 9,"type" : "label", "title":"开始日期", "value": "2018-11-16"],
                ["id": 10, "type": "input", "title": "备注", "value": ""],
                //            ["id": 7,"type" : "Button", "ary": ["title":"删除", "color": "red"]],
                ["id": 11,"type" : "button", "title":"新建模版", "color": "blue"],
                ],
                              "indexId": 0,
                              "id": ""
                ]]
        }

        
        // 配置信息
        let configDic = NSDictionary.init(contentsOfFile: NSHomeDirectory() + "/Library/Caches/config.plist")
        self.configData = JSON.init(configDic as Any)
        
        // 复制第一个模版
        
        if self.inletName == "医生出诊" {
            
            self.copyDataList = ["itme" : [
                
              
                ["id": 0, "type": "labelArrow", "title":"药品名称", "value": "", "placeholder": "请输入药品名称"],
                ["id": 1, "type": "dropDown", "title":"服药次数","value": "一日1次"],
                ["id": 2, "type": "dropDown", "title": "吃药时间1", "value":"07:00", "isHides" : false],
                ["id": 3, "type": "dropDown", "title": "吃药时间2", "value":"07:10", "isHides" : true],
                ["id": 4, "type": "dropDown", "title": "吃药时间3", "value":"07:20", "isHides" : true],
                ["id": 5, "type": "dropDown", "title": "吃药时间4", "value":"07:30", "isHides" : true],
                
                
                ["id": 6, "type": "radio", "title": "服药时段", "value": "餐前", "itemAry": [["select": false, "title": "餐前"],["select": true, "title": "餐后"]]],
                ["id": 7, "type" : "labelArrow", "title":"用量(剂量)","value": "请选择"],
                ["id": 8,"type" : "labelArrow", "title":"疗程",  "value": ""],
//                ["id": 9,"type" : "label", "title":"开始日期", "value": "2018-11-16"],
                
                //            ["id": 7,"type" : "Button", "ary": ["title":"删除", "color": "red"]],
                ["id": 10,"type" : "button", "title":"新建模版", "color": "blue"],
                ],
                   "indexId": 0,
                   "prescId": "", //疾病id
                   "id": ""
                ]
            
        }else {
            self.copyDataList = self.dataList[0]
        }
        
        
        
        // 有数据时进入
        if reminderJson.count > 0 {
                
                if self.inletName == "医生出诊" {

                    let id = reminderJson["id"].stringValue
                    if id != "" {
                        self.dataList[0]["prescId"].stringValue = id
                    }
                    let applyIllness = reminderJson["applyIllness"].stringValue //疾病名称
                    if applyIllness != "" {
                        self.dataList[0]["itme"][0]["value"].stringValue = applyIllness
                    }
                    
                    let medicines =  reminderJson["medicines"]
                    
                    for n in 0..<medicines.count {
                        let medic = medicines[n]
                        
                        for item in medic {
                            print("=======>>", item)
                        }
                    }

                    
                }else { //提醒部分
                    
                    // 循环每个模块版
                    for n in 0..<reminderJson.count {
                    
                      let reminder =  reminderJson[n]  // 获取每个模块
                    
                      for item in reminder {
                        if item.0 == "medicineName" {
                            self.dataList[n]["itme"][0]["value"].stringValue = "\(item.1)"
                        }else if item.0 == "timesOneDay" {
                            var config = configData![item.0]
                            let num = (item.1.intValue - 1)
                            self.dataList[n]["itme"][1]["value"].stringValue = config[num]["desc"].stringValue
                        }else if item.0 == "reminderTime" {
                            let ary = item.1.arrayValue
                            for i in 0..<ary.count {
                                self.dataList[n]["itme"][2 + i]["isHides"].stringValue = "false"
                                self.dataList[n]["itme"][2 + i]["value"].stringValue = ary[i].stringValue
                            }
                            
                            if ary.count < 4 {
                                for j in 0..<(4 - ary.count) {
                                    dataList[n]["itme"][2 + ary.count + j]["isHides"].stringValue = "true"
                                }
                            }
                            
                        }else if item.0 == "takeTime" {
                            var config = configData![item.0]
                            let num = (item.1.intValue - 1)
                            self.dataList[n]["itme"][6]["value"].stringValue = config[num]["desc"].stringValue
                            
                            if num == 0 {
                                self.dataList[n]["itme"][6]["itemAry"][num]["select"].stringValue = "true"
                                self.dataList[n]["itme"][6]["itemAry"][num + 1]["select"].stringValue = "false"
                            }else {
                                self.dataList[n]["itme"][6]["itemAry"][num]["select"].stringValue = "true"
                                self.dataList[n]["itme"][6]["itemAry"][num - 1]["select"].stringValue = "false"
                            }
                            
                            
                            
                        }else if item.0 == "dosage" {
                            var config = configData![item.0]
                            let num = (item.1.intValue - 1)
                            var newStr = self.dataList[n]["itme"][7]["value"].stringValue
                            
                            if newStr == "请选择" {
                                newStr = ""
                            }
                            self.dataList[n]["itme"][7]["value"].stringValue = "一次\(config[num]["desc"].stringValue)\(newStr)"
                            
                        }else if item.0 == "dosageUnit" {
                            var config = configData![item.0]
                            let num = (item.1.intValue - 1)
                            var newStr = self.dataList[n]["itme"][7]["value"].stringValue
                            
                            if newStr == "请选择" {
                                newStr = ""
                            }
                            self.dataList[n]["itme"][7]["value"].stringValue = "\(newStr)\(config[num]["desc"].stringValue)"
                            
                        }else if item.0 == "startTime" {
                            var config = configData![item.0]
                            let str =  String.chineseTime(frome: item.1.stringValue)
                            
                            self.dataList[n]["itme"][9]["value"].stringValue = str.substring(toIndex: 11)
                        }else if item.0 == "remark" {
                            self.dataList[n]["itme"][10]["value"].stringValue = "\(item.1)"
                        }
                        
                        
                    }
                        
                    }
                }
                
               
            
            
        }

    }
    
    

    
    
    /// 请求url
    /// 请求数据
    /// 返回
    func requestData(urlString: String, bodyData:Data, block:((_ body: Data?) ->(Void))?) {
//        let bodyStr = self.getJSONString(array: par)
//        let bodyData = bodyStr.data(using: String.Encoding.utf8)
//        let urlString = configure.shareConfigure.IP + "user/medicine/reminder"
        let url = URL.init(string: urlString)
        let request =  NSMutableURLRequest.init(url: url!)//application/json;charset=UTF-8
        request.httpMethod = "post"
        request.setValue(NetRequestTool.shareInstance.token, forHTTPHeaderField: "Authorization")
        request.setValue("application/json", forHTTPHeaderField: "Content-Type")
        request.httpBody = bodyData
        // 9.0以前
        //        NSURLConnection.sendAsynchronousRequest(<#T##request: URLRequest##URLRequest#>, queue: <#T##OperationQueue#>, completionHandler: <#T##(URLResponse?, Data?, Error?) -> Void#>)
        // NSURLSession dataTaskWithRequest:completionHandler:
    
        let session = URLSession.shared
        let task = session.dataTask(with: request as URLRequest) { (_data, _response, _err) in
//            let str = String.init(data: _data!, encoding: String.Encoding.utf8)
//            print("1=====>>", str)
//            print("2=====>>", _response!)
            
            block?(_data!)
        }
        task.resume()
    }
}

extension HMRemindMatter: UITableViewDelegate, UITableViewDataSource {
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.dataList.count
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
//        print("第er次打印", self.cellHeight)
        return self.cellHeight
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let item = dataList[indexPath.row].dictionaryValue
        let data = JSON.init(item)   //init(dictionaryLiteral: dat)
        let cell = HMRemindMatterCell.cell(json: data, tableView: tableView, cellForRowAt: indexPath)
        cell?.selectionStyle = UITableViewCellSelectionStyle.none
        cell?.delegate = self
        self.cellHeight = 0.0 //重置
        self.cellHeight = (cell?.cellHeight)!
        return cell!
    }
}


extension HMRemindMatter: HMRemindMatterCellDelegate {
    func matterCell(_ id: Int, itemType: String, view: MatterItemView, cellInt: IndexPath, itemTag: Int, value: Any?, itemJson: JSON) {
     //   print("\(cellInt)==tag:\(itemTag)====>\(itemType)---->\n => \(view)  json: \(itemJson)")
        
        if itemType == "labelArrow" {
            if view.title.text == "药品名称" {
                let drugs = HMDrugs()
                drugs.drugsBlock = {
                   (value) -> () in
                    print("===》〉", value)
                     self.dataList[cellInt.row]["itme"][itemTag]["value"].stringValue = value
                     self.table.reloadRows(at: [cellInt], with: UITableViewRowAnimation.none)
                    
                }
                self.pushViewController(drugs)
            }else if view.title.text == "用量(剂量)" {
                HMPickerView.creator(nil, picker: ["AryList": [self.dosePickAry,self.companyAry]])
                HMPickerView.sharePicker.rowArrayViewBlock = {
                    (picker, ary) -> ()in
                    
                    let newAry =  ary as! Array<(row: Int, com: Int)>
                    
                    let item1 = self.dosePickAry[newAry[0].row]
                    let item2 = self.companyAry[newAry[1].row]
                    
                    self.dataList[cellInt.row]["itme"][itemTag]["value"].stringValue = "\(item1)"+"\(item2)"
                    self.table.reloadData()
//                    self.table.reloadRows(at: [cellInt], with: UITableViewRowAnimation.none)
                }
            }
            else if view.title.text == "疗程" {
                HMPickerView.creator(nil, picker: ["Ary": self.coursePickAry])
                HMPickerView.sharePicker.rowComViewBlock = {
                    (picker, row, com) -> ()in
                    
                    
                    let str = self.coursePickAry[row]
                    self.dataList[cellInt.row]["itme"][itemTag]["value"].stringValue = str
                    self.table.reloadRows(at: [cellInt], with: UITableViewRowAnimation.none)
                }
            }
        }
        
        
        if itemType == "button" {
            let str = value as! String
            if str == "新建模版" { //添加
                
                // 拷贝第一个
                var newData =  self.copyDataList
                newData["indexId"].intValue =  self.dataList.count
                
                var copyData = self.dataList.arrayValue
                let num = self.dataList.count - 1
                
                // 更改第一个数据
                copyData[num]["itme"][itemTag]["title"].stringValue = "删除"
                copyData[num]["itme"][itemTag]["color"].stringValue = "red"
                copyData.append(newData)
                

                self.dataList =  JSON.init(copyData)

                let indexPath = IndexPath.init(row:(cellInt.row + 1), section: 0)
                table.insertRows(at: [indexPath], with: UITableViewRowAnimation.bottom)
                
                let newIndexPath = cellInt //IndexPath.init(row:cellInt.row, section: 0)
                self.table.reloadRows(at: [newIndexPath], with: UITableViewRowAnimation.none)
               
            }else {
                // 删除
//                self.dataList.remove(at: cellInt)
                var newList = self.dataList.arrayValue
                newList.remove(at: cellInt.row)
                
                self.dataList = JSON.init(newList)
                let cellIndexPath = cellInt //IndexPath.init(row: cellInt, section: 0)
                self.table.deleteRows(at: [cellIndexPath], with: .fade)
                self.table.reloadData()
            }
        }
        
        if itemType == "dropDown" {  // 注意事项： dropdown 返回的 cellInt 变成 itemtag, 原来cellInt 使用 id , itemTag是 选择的子项
            
            if  view.title.text == "服药次数" {
                HMPickerView.creator(nil, picker: ["Ary": self.numPickerAry])
                HMPickerView.sharePicker.rowComViewBlock = {
                    (picker, row, com) -> ()in
                    
                    
                    let str = self.numPickerAry[row]
                    self.dataList[cellInt.row]["itme"][itemTag]["value"] = JSON(str)
                    for  ie in  0..<self.numPickerAry.count {
                   
                        if ie < (row+1) {
                            let num = itemTag + ie + 1
//                                 print("false=====>>", num)
                            self.dataList[cellInt.row]["itme"][num]["isHides"] = "false"
                        }else {
                            let num = itemTag + ie + 1
                            self.dataList[cellInt.row]["itme"][num]["isHides"] = "true"
                        }
                    }
                    let newIndexPath = cellInt //IndexPath.init(row:cellInt, section: 0)
                    self.table.reloadData()
//                    self.table.reloadRows(at: [newIndexPath], with: UITableViewRowAnimation.none)
                }
                
            }else if (view.title.text?.contains("吃药时间"))! {
                HMPickerView.creator(nil, picker: ["AryList": [self.hourAry,self.minuteAry]])
                HMPickerView.sharePicker.rowArrayViewBlock = {
                    (picker, ary) -> ()in
                    let newAry =  ary as! Array<(row: Int, com: Int)>
                    let item1 = self.hourAry[newAry[0].row].prefix(2)
                    let item2 = self.minuteAry[newAry[1].row].prefix(2)
                    
                    self.dataList[cellInt.row]["itme"][itemTag]["value"].stringValue = "\(item1):\(item2)"
                    self.table.reloadData()
//                     self.table.reloadRows(at: [cellInt], with: UITableViewRowAnimation.none)
                }
            }

        }
        
        
        if itemType == "radio" {
            let v =  value as! String
            if v == "0" {
                self.dataList[cellInt.row]["itme"][itemTag]["itemAry"][0]["select"] = "true"
                self.dataList[cellInt.row]["itme"][itemTag]["itemAry"][1]["select"] = "false"
            }else {
                self.dataList[cellInt.row]["itme"][itemTag]["itemAry"][1]["select"] = "true"
                self.dataList[cellInt.row]["itme"][itemTag]["itemAry"][1 - 1]["select"] = "false"
            }
            
             self.table.reloadRows(at: [cellInt], with: UITableViewRowAnimation.none)
  
        }
        
        if itemType ==  "input" {
            if view.title.text == "疾病名称" {
                self.dataList[cellInt.row]["itme"][itemTag]["value"].stringValue = value as! String
            }else if  view.title.text == "备注" {
                print("====>>")
                self.dataList[cellInt.row]["itme"][itemTag]["value"].stringValue = value as! String
            }
        }
    }
    
    @objc func clickMark(sender: UITapGestureRecognizer) {
        HMPickerView.hidePickeView()
        self.maskView?.removeFromSuperview()
    }
    
}
